#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;


int dfs(int x,int y,int n,int m,int *adj,int *mem){
	if(mem[y*m+x] != -1)
		return mem[y*m+x];
	int l=0,r=0,u=0,d=0,ans=0;
	if(x != 0  &&  adj[y*m+x] > adj[y*m+x-1])
		l = dfs(x-1,y,n,m,adj,mem);
	if(x != m-1  &&  adj[y*m+x] >adj[y*m+x+1])
		r = dfs(x+1,y,n,m,adj,mem);
	if(y != 0  &&  adj[y*m+x] > adj[(y-1)*m+x])
		u = dfs(x,y-1,n,m,adj,mem);
	if(y != n-1  &&  adj[y*m+x] > adj[(y+1)*m+x])
		d = dfs(x,y+1,n,m,adj,mem);
	ans = max(max(l,r),max(u,d))+1;
	mem[y*m+x] = ans;
	return ans;
}



int main(){
	int n,m,ans=0;
	cin>>n>>m;
	int adj[n][m],mem[n][m];
	memset(&mem[0][0],-1,sizeof(mem));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int l;
			cin>>l;
			adj[i][j] = l;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int l=dfs(j,i,n,m,&adj[0][0],&mem[0][0]);
			ans = max(ans,l);
		}
	}
	cout<<ans;
}
